
#include <middleware/mk_lib/mk_auto_mutex.h>
#include <middleware/os/os_env.h>
#include "gm_sc_mgr.h"
#include "gm_sc_app.h"
#include "gm_sc_cont.h"
#include "gm_handle.h"

mk_mutex g_mutex;

gm_sc_dev_mgr gm_sc_mgr::_g_dev_mgr;

ULONG gm_sc_mgr::lock_dev( HANDLE hdev, ULONG ulTimeOut)
{
	ULONG			lRslt = SAR_OK;
	gm_sc_dev		*pdev = gm_sc_mgr::get_dev_ptr()->get_dev_by_handle(hdev);

	TRACE_ASSERT(hdev && strlen(pdev->Name()) > 0)
	pdev->lock_dev(ulTimeOut);
	
END_OF_FUN:
	return lRslt;
}

ULONG gm_sc_mgr::unlock_dev( HANDLE hdev)
{
	ULONG			lRslt = SAR_OK;
	char			szMutexName[64] = {0};
	gm_sc_dev		*pdev = gm_sc_mgr::get_dev_ptr()->get_dev_by_handle(hdev);

	TRACE_ASSERT(hdev && strlen(pdev->Name()) > 0)

	pdev->unlock_dev();

END_OF_FUN:
	return lRslt;
}

gm_sc_dev_mgr *gm_sc_mgr::get_dev_ptr()
{
	return &_g_dev_mgr;
}	
